home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / text / misc / MSWordView_src.lha / mswordview / stylesheet.c < prev    next >
C/C++ Source or Header  |  1998-12-14  |  7KB  |  262 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include "config.h"
  6. #include "mswordview.h"
  7.  
  8. int nostyles;
  9.  
  10. extern FILE *erroroutput;
  11.  
  12. style *decode_stylesheet(FILE *tablefd,U32 stsh,U32 stshlen)
  13.     {
  14.     U16 sprm=0;
  15.     U16 j;
  16.     int i,upxbytes,len,m;
  17.     U16 thingy;
  18.     
  19.     U16 cb;
  20.     style *stylelist;
  21.     U16 pos;
  22.     int baseistd;
  23.     int tempistd;
  24.  
  25.     error(erroroutput,"the new stsh is (%x), len (%x)\n",stsh,stshlen);
  26.  
  27.     fseek(tablefd,stsh,SEEK_SET);
  28.     error(erroroutput,"not really stsh size is %ld\n",read_16ubit(tablefd));
  29.     
  30.     nostyles = read_16ubit(tablefd);
  31.     error(erroroutput,"count of styles is %d\n",nostyles);
  32.     error(erroroutput,"cbSTDBaseInFile is %ld\n",read_16ubit(tablefd));
  33.     for (i=0;i<7;i++)
  34.         read_16ubit(tablefd);
  35.  
  36.     stylelist = (style *) malloc(sizeof(style) * nostyles);
  37.     if (stylelist == NULL)
  38.         {
  39.         fprintf(erroroutput,"arse no mem for styles !\n");
  40.         exit(-1);
  41.         }
  42.     
  43.     for (m=0;m<nostyles;m++)
  44.         {
  45.         cb = read_16ubit(tablefd);
  46.         error(erroroutput,"size of std %ld\n",cb);
  47.  
  48.         init_pap(&stylelist[m].thepap);
  49.  
  50.         init_chp(&stylelist[m].thechp);
  51.         
  52.         error(erroroutput,"m val is %d\n",m);
  53.  
  54.         if (cb != 0)
  55.             {
  56.             pos=0;
  57.  
  58.             read_16ubit(tablefd);
  59.             pos+=2;
  60.             j = read_16ubit(tablefd);
  61.             pos+=2;
  62.             baseistd = j>>4;
  63.             error(erroroutput,"based upon istd is %d %d",j,baseistd);
  64.             if (baseistd < 0x0ffe)    
  65.                 {
  66.                 if (baseistd < m)
  67.                     fill_pap(stylelist,m,baseistd);
  68.                 else
  69.                     error(erroroutput,"how can i be based on a style that i havent seen yet?\n");
  70.                 }
  71.             else
  72.                 error(erroroutput,"WARNING strange and unsupported istd base %x\n",baseistd);
  73.             j = read_16ubit(tablefd);
  74.             pos+=2;
  75.             error(erroroutput,"# of upx is %d %d\n",j,j>>12); 
  76.             upxbytes = j;
  77.             for (i=0;i<2;i++)
  78.                 {
  79.                 read_16ubit(tablefd);
  80.                 pos+=2;
  81.                 }
  82.             len = read_16ubit(tablefd);
  83.             pos+=2;
  84.             error(erroroutput,"name len is %d,\n",len);
  85.             for(i=0;i<len+1;i++)
  86.                 {
  87.                 thingy = read_16ubit(tablefd);
  88.                 pos+=2;
  89.                 error(erroroutput,"thingy is %ld (%X) (-%x-) (-%c-)\n",thingy,thingy,thingy,thingy);
  90.                 }
  91.  
  92.             error(erroroutput,"pos is %x and %d",ftell(tablefd),pos);
  93.  
  94.             if ((pos+1)/2 != pos/2)
  95.                 {
  96.                 /*eat odd bytes*/
  97.                 error(erroroutput,"odd offset\n");
  98.                 fseek(tablefd,1,SEEK_CUR);
  99.                 pos++;
  100.                 }
  101.  
  102.             if (pos == cb)
  103.                 {
  104.                 error(erroroutput,"continuing\n");
  105.                 continue;
  106.                 }
  107.             else if (pos > cb)
  108.                 {
  109.                 error(erroroutput,"rewinding & continuing\n");
  110.                 fseek(tablefd,cb-pos,SEEK_CUR);
  111.                 continue;
  112.                 }
  113.             if ((pos+1)/2 != pos/2)
  114.                 {
  115.                 /*eat odd bytes*/
  116.                 error(erroroutput,"odd offset\n");
  117.                 fseek(tablefd,1,SEEK_CUR);
  118.                 pos++;
  119.                 }
  120.  
  121.             if (pos == cb)
  122.                 {
  123.                 error(erroroutput,"continuing\n");
  124.                 continue;
  125.                 }
  126.             else if (pos > cb)
  127.                 {
  128.                 error(erroroutput,"rewinding & continuing\n");
  129.                 fseek(tablefd,cb-pos,SEEK_CUR);
  130.                 continue;
  131.                 }
  132.  
  133.             /*read some kind of len variable, hairy territory again*/
  134.             upxbytes = read_16ubit(tablefd);
  135.             pos+=2;
  136.             error(erroroutput,"1 eat %d bytes",upxbytes);
  137.             j=0;
  138.             if (upxbytes > 1)
  139.                 {
  140.                 tempistd = read_16ubit(tablefd);
  141.                 pos+=2;
  142.                 j+=2;
  143.                 if (tempistd != m)
  144.                     {
  145.                     error(erroroutput,"istds mismatch is %x %x\n",m,tempistd);
  146.                     /*treat it as a sprm instead*/
  147.                     sprm = tempistd;
  148.                     }
  149.                 else
  150.                     {
  151.                     if (j < upxbytes)
  152.                         {
  153.                         sprm = read_16ubit(tablefd);
  154.                         j+=2;
  155.                         pos+=2;
  156.                         }
  157.                     }
  158.                 }
  159.  
  160.             while (j<upxbytes)
  161.                 {
  162.                 error(erroroutput," j was %d\n",j);
  163.                 pos-=j;
  164.                 decode_sprm(tablefd,sprm,&(stylelist[m].thepap),&(stylelist[m].thechp),NULL,&j,NULL,stylelist,stylelist[m].thepap.istd);
  165.                 error(erroroutput," j is %d\n",j);
  166.                 pos+=j;
  167.                 if (j>=upxbytes)
  168.                     break;
  169.                 sprm = read_16ubit(tablefd);
  170.                 j+=2;
  171.                 pos+=2;
  172.                 }
  173.  
  174.             if ((pos+1)/2 != pos/2)
  175.                 {
  176.                 /*eat odd bytes*/
  177.                 error(erroroutput,"odd offset\n");
  178.                 fseek(tablefd,1,SEEK_CUR);
  179.                 error(erroroutput,"were at %x\n",ftell(tablefd));
  180.                 pos++;
  181.                 }
  182.  
  183.             if (pos == cb)
  184.                 {
  185.                 error(erroroutput,"continuing\n");
  186.                 continue;
  187.                 }
  188.             else if (pos > cb)
  189.                 {
  190.                 error(erroroutput,"rewinding & continuing\n");
  191.                 fseek(tablefd,cb-pos,SEEK_CUR);
  192.                 continue;
  193.                 }
  194.  
  195.             /*then this is the len of bytes of the next stuff*/
  196.             upxbytes = read_16ubit(tablefd);
  197.             pos+=2;
  198.             error(erroroutput,"2 eat %d bytes",upxbytes);
  199.  
  200.             /*k this is the good stuff*/
  201.             j=0;
  202.             while (j < upxbytes)
  203.                 {
  204.                 sprm = read_16ubit(tablefd);
  205.                 j+=2;
  206.                 pos+=2;
  207.                 error(erroroutput," j was %d\n",j);
  208.                 pos-=j;
  209.                 decode_sprm(tablefd,sprm,&(stylelist[m].thepap),&(stylelist[m].thechp),NULL,&j,NULL,stylelist,stylelist[m].thepap.istd);
  210.                 error(erroroutput," j is %d\n",j);
  211.                 pos+=j;
  212.                 }
  213.             
  214.             if ((pos+1)/2 != pos/2)
  215.                 {
  216.                 /*eat odd bytes*/
  217.                 error(erroroutput,"odd offset\n");
  218.                 fseek(tablefd,1,SEEK_CUR);
  219.                 pos++;
  220.                 }
  221.  
  222.             error(erroroutput,"m val %d, ilfo is %d\n",m,stylelist[m].thepap.ilfo);
  223.             }
  224.         }
  225.     return(stylelist);
  226.     }
  227.  
  228.  
  229. void fill_pap(style *stylelist,int m,int b)
  230.     {
  231.     stylelist[m].thepap.fInTable = stylelist[b].thepap.fInTable;
  232.     stylelist[m].thepap.fTtp= stylelist[b].thepap.fTtp;
  233.     stylelist[m].thepap.ilvl = stylelist[b].thepap.ilvl;
  234.     stylelist[m].thepap.ilfo = stylelist[b].thepap.ilfo;
  235.     stylelist[m].thepap.list_data=stylelist[b].thepap.list_data;
  236.     stylelist[m].thepap.leftmargin=stylelist[b].thepap.leftmargin;
  237.     stylelist[m].thepap.firstline=stylelist[b].thepap.firstline;
  238.  
  239.     stylelist[m].thechp.fBold=stylelist[b].thechp.fBold;
  240.     stylelist[m].thechp.fItalic=stylelist[b].thechp.fItalic;
  241.     stylelist[m].thechp.fCaps =stylelist[b].thechp.fCaps;
  242.     stylelist[m].thechp.animation=stylelist[b].thechp.animation;
  243.     stylelist[m].thechp.ascii_font=stylelist[b].thechp.ascii_font;
  244.     stylelist[m].thechp.eastfont=stylelist[b].thechp.eastfont;
  245.     stylelist[m].thechp.noneastfont=stylelist[b].thechp.noneastfont;
  246.     stylelist[m].thechp.fontsize=stylelist[b].thechp.fontsize;
  247.     stylelist[m].thechp.supersubscript= stylelist[b].thechp.supersubscript;
  248.     stylelist[m].thechp.fontcode=stylelist[b].thechp.fontcode;
  249.     stylelist[m].thechp.fontspec=stylelist[b].thechp.fontspec;
  250.     strcpy(stylelist[m].thechp.color,stylelist[b].thechp.color);
  251.     stylelist[m].thechp.underline=stylelist[b].thechp.underline;
  252.     stylelist[m].thechp.fSpec=stylelist[b].thechp.fSpec;
  253.     stylelist[m].thechp.fObj=stylelist[b].thechp.fObj;
  254.     stylelist[m].thechp.idctHint=stylelist[b].thechp.idctHint;
  255.     stylelist[m].thechp.fcPic=stylelist[b].thechp.fcPic;
  256.     stylelist[m].thechp.fData=stylelist[b].thechp.fData;
  257.     stylelist[m].thechp.fStrike=stylelist[b].thechp.fStrike;
  258.     stylelist[m].thechp.fDStrike=stylelist[b].thechp.fDStrike;
  259.  
  260.     }
  261.  
  262.